package com.example.rabc.common;

import lombok.Data;

@Data
/**
 * API 响应类，用于统一返回 API 接口的响应结果
 * @param <T> 响应数据的类型
 */
public class ApiResponse<T> {
    private boolean success;
    private int code;
    private String message;
    private T data;
    
    public static <T> ApiResponse<T> success(T data) {
        ApiResponse<T> response = new ApiResponse<>();
        response.success = true;
        response.code = 200;
        response.message = "操作成功";
        response.data = data;
        return response;
    }
    
    public static <T> ApiResponse<T> error(String message) {
        ApiResponse<T> response = new ApiResponse<>();
        response.success = false;
        response.code = 500;
        response.message = message;
        response.data = null;
        return response;
    }
    
    public static <T> ApiResponse<T> error(int code, String message) {
        ApiResponse<T> response = new ApiResponse<>();
        response.success = false;
        response.code = code;
        response.message = message;
        response.data = null;
        return response;
    }
}